package com.leetcode.array_matrix;

/**
 * @author Dennis Li
 * @date 2020/11/1 17:08
 */
public class ThirdMax_414 {

    public int thirdMax(int[] nums) {
        long first = Long.MIN_VALUE, second = Long.MIN_VALUE, third = Long.MIN_VALUE;
        for (int num : nums) {
            if (num > first) {
                long temp1 = first, temp2 = second;
                first = num;
                second = temp1;
                third = temp2;
            } else if (num < first && num > second) {
                long temp = second;
                second = num;
                third = temp;
            } else if (num < second && num > third) {
                third = num;
            }
        }
        return third == Long.MIN_VALUE ? (int) first : (int) third;
    }

}
